package com.ztsoft.user.controller.user;

import com.ztsoft.user.pojo.entity.user.SysUser;
import com.ztsoft.user.pojo.vo.user.SysUserVo;
import com.ztsoft.user.service.user.SysUserService;
import com.ztsoft.user.utils.Result;
import com.ztsoft.user.pojo.enums.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/user")
@CrossOrigin("*")
@Api(tags = "用户控制层")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @PutMapping("/manageUser")
    @ApiOperation(value = "一键添加用户至管理员管理", notes = "一键添加用户至管理员管理")
    public Result<Object> manageUser() {
        return sysUserService.manageUser();
    }

    @PutMapping("/manageProject")
    @ApiOperation(value = "一键添加项目至管理员管理", notes = "一键添加项目至管理员管理")
    public Result<Object> manageProject() {
        return sysUserService.manageProject();
    }

    @GetMapping("/queryByPage")
    @ApiOperation(value = "查询用户", notes = "带分页的条件查询")
    public Result<Object> queryByPage(SysUser user, Integer currentPage, Integer pageSize) {
        return sysUserService.queryUserByPage(user, currentPage, pageSize);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加用户", notes = "添加用户")
    public Result<Object> add(@RequestBody SysUserVo sysUserVo) {
        return sysUserService.addUser(sysUserVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新用户", notes = "更新用户")
    public Result<Object> update(@RequestBody SysUserVo sysUserVo) {
        return sysUserService.updateUser(sysUserVo);
    }

    @PutMapping("/changePassword")
    @ApiOperation(value = "修改密码", notes = "修改密码")
    public Result<Object> changePassword(@RequestBody SysUserVo sysUserVo) {
        return sysUserService.changePassword(sysUserVo);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除用户", notes = "按照id删除用户")
    public Result<Object> delete(@PathVariable("id") String id) {
        return sysUserService.deleteUser(id);
    }

    @GetMapping("/noAuth")
    @ApiOperation(value = "无权限接口", notes = "无权限接口")
    public Result<Object> noAuth() {
        return Result.returnMsg(ResultCode.NO_PERMISSION.getMsg(), ResultCode.NO_PERMISSION.getCode());
    }

    @PostMapping("/login")
    @ApiOperation(value = "用户登录", notes = "用户登录")
    public Result<Object> login(@RequestBody Map<String, Object> map) {
        return sysUserService.login(map);
    }

    @GetMapping("/toLogin")
    @ApiOperation(value = "拦截接口", notes = "拦截接口")
    public Result<Object> toLogin() {
        return Result.returnMsg(ResultCode.USER_NOT_LOGIN.getMsg(), ResultCode.USER_NOT_LOGIN.getCode());
    }

    @GetMapping("getInfo")
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    public Result<Object> getInfo() {
        return sysUserService.getInfo();
    }

    @GetMapping("getRouters")
    @ApiOperation(value = "获取路由信息", notes = "获取路由信息")
    public Result<Object> getRouters() {
        return sysUserService.getRouters();
    }

}